﻿using System;
using System.Collections.Generic;
using System.Management;
using System.Text;

namespace SharpSoft.OS
{
    public static class Windows
    {


        public static string GetCPUID()
        {
            try
            { 
                ManagementClass mc = new ManagementClass("Win32_Processor");
                ManagementObjectCollection moc = mc.GetInstances();
                string strCpuID = null;
                foreach (ManagementObject mo in moc)
                {
                    strCpuID = mo.Properties["ProcessorId"].Value.ToString();
                    mo.Dispose();
                    break;
                }
                return strCpuID;
            }
            catch
            {
                return "";
            }
        } 
        /// <summary>
        /// 获取主板UUID
        /// </summary>
        /// <returns></returns>
        public static string GetBaseBoardUUID()
        {
            //主板
            ManagementClass mc2 = new ManagementClass("Win32_ComputerSystemProduct");
            ManagementObjectCollection moc2 = mc2.GetInstances();

            foreach (ManagementObject mo in moc2)
            { 
               return mo.Properties["UUID"].Value.ToString();
            }
            return "";
        }

        /// <summary>
        /// 获取硬盘串号
        /// </summary>
        /// <returns></returns>
        public static string GetHardDiskSerialNumber()
        {

            //硬盘
            ManagementClass mc3 = new ManagementClass("Win32_PhysicalMedia");
            //网上有提到，用Win32_DiskDrive，但是用Win32_DiskDrive获得的硬盘信息中并不包含SerialNumber属性。   
            ManagementObjectCollection moc3 = mc3.GetInstances();
            foreach (ManagementObject mo in moc3)
            {
                return mo.Properties["SerialNumber"].Value.ToString(); 
            }
            return "";
        }
         
    }
}
